<?php echo $header;echo $sidebar ?>		

	<style>
		select {background-color: #FFFFFF;border: 1px solid #CCCCCC;width: 100% !important;}
		.clear{clear: both;}
		.row:before, .row:after {
    content: " ";
    display: table;
}
.row:before, .row:after {
    content: " ";
    display: table;
}
.row:before, .row:after {
    content: " ";
    display: table;
}
.row:before, .row:after {
    content: " ";
    display: table;
}
.row:before, .row:after {
    content: " ";
    display: table;
}
.row:after {
    clear: both;
}
.row:before, .row:after {
    content: " ";
    display: table;
}
.row:after {
    clear: both;
}
.row:before, .row:after {
    content: " ";
    display: table;
}
.row:after {
    clear: both;
}
.row:before, .row:after {
    content: " ";
    display: table;
}
.row:after {
    clear: both;
}
.row:before, .row:after {
    content: " ";
    display: table;
}
.row:after {
    clear: both;
}
.row:before, .row:after {
    content: " ";
    display: table;
}

.col-lg-1 {
    margin-bottom: 10px;
    width: 15%;
}
.col-lg-1 {
    width: 8.33333%;
}
.col-lg-1, .col-lg-2, .col-lg-3, .col-lg-4, .col-lg-5, .col-lg-6, .col-lg-7, .col-lg-8, .col-lg-9, .col-lg-10, .col-lg-11 {
    float: left;
}
.col-xs-1, .col-xs-2, .col-xs-3, .col-xs-4, .col-xs-5, .col-xs-6, .col-xs-7, .col-xs-8, .col-xs-9, .col-xs-10, .col-xs-11, .col-xs-12, .col-sm-1, .col-sm-2, .col-sm-3, .col-sm-4, .col-sm-5, .col-sm-6, .col-sm-7, .col-sm-8, .col-sm-9, .col-sm-10, .col-sm-11, .col-sm-12, .col-md-1, .col-md-2, .col-md-3, .col-md-4, .col-md-5, .col-md-6, .col-md-7, .col-md-8, .col-md-9, .col-md-10, .col-md-11, .col-md-12, .col-lg-1, .col-lg-2, .col-lg-3, .col-lg-4, .col-lg-5, .col-lg-6, .col-lg-7, .col-lg-8, .col-lg-9, .col-lg-10, .col-lg-11, .col-lg-12 {
    min-height: 1px;
    padding-left: 15px;
    padding-right: 15px;
    position: relative;
}
	</style>
	

	

	<div class="span10 content">
		
		<?php echo $hugemenu ?>
		
		<div class="row" style="padding:15px;">
			<div class="col-lg-12">
				<?php 
		        $error = $this->session->flashdata('error');
		            	
		        if($error)
		        {
		        	echo "<div class='alert alert-danger'>{$error}</div>";
		        } ?>
		        
		        <h3>
		        	<?php echo $department[0]['department_name']; ?> 
		        	<?php 
					if($department[0]['department_is_default'])
					{
						echo "<span>(Default)</span>";
					} ?>
					
					<?php 
					if($this->session->userdata('level'))
					{ ?>
						<span class="pull-right hidden-lg">
							<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#edit-department">Edit</button>
						</span>
					<?php 
					} ?>
					
					<span class="pull-right visible-lg">
						<?php 
						if($this->session->userdata('level'))
						{ ?>
							<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#edit-department">Edit</button> 
						<?php 
						} ?>
						
						<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#new-attachment">Attach</button>
						
						<?php 
						if(!$department[0]['department_is_default'])
						{
							if($this->session->userdata('level'))
							{
								if($department[0]['department_is_active'])
			                    { ?>
			                    	<a href="<?php echo base_url(); ?>index.php/departments/deactivate/<?php echo $department[0]['department_id']; ?>"><button type="button" class="btn btn-primary">Deactivate</button></a>
			                    <?php 
			                    } 
			                    else
			                    { ?>
			                      	<a href="<?php echo base_url(); ?>index.php/departments/activate/<?php echo $department[0]['department_id']; ?>"><button type="button" class="btn btn-primary">Activate</button></a>
			                    <?php 
			                    } 
			                } ?>
		                    
		                    <?php 
							if($this->session->userdata('level'))
							{ ?>
		                    	<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#delete-department">Delete</button>
		                    <?php 
							} ?>
		                <?php 
		                } ?>
					</span>
				</h3>
				<hr>
			  	
			  	<?php 
				if($this->session->userdata('level'))
				{ ?>
				  	<div class="modal fade" id="delete-department" tabindex="-1" role="dialog" aria-labelledby="delete-department-label" aria-hidden="true">
				    	<div class="modal-dialog">
				      		<div class="modal-content">
				        		<div class="modal-header">
				          			<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				          			<h4 class="modal-title">Delete Department</h4>
				        		</div>
				        		<div class="modal-body">
				        			Are you sure you want to delete <?php echo $department[0]['department_name']; ?>?
				        		</div>
				        		<div class="modal-footer">
				          			<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
				          			<a href="<?php echo base_url(); ?>departments/delete/<?php echo $department[0]['department_id']; ?>"><button type="button" class="btn btn-primary">Delete</button></a>
				        		</div>
				      		</div>
				    	</div>
				  	</div>
				<?php 
				} ?>
			  	
			  	<div class="modal fade" id="new-attachment" tabindex="-1" role="dialog" aria-labelledby="new-attachment-label" aria-hidden="true">
			    	<div class="modal-dialog">
			      		<div class="modal-content">
			        		<div class="modal-header">
			          			<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
			          			<h4 class="modal-title">Add New Attachment</h4>
			        		</div>
			        		<div class="modal-body">
			        			<form id="new-attachment-form" action="<?php echo base_url(); ?>departments/upload/<?php echo $department[0]['department_id']; ?>" enctype="multipart/form-data" method="post">
			          				<input type="file" name="file">
			          				<br>
			          				<textarea name="description" class="form-control" rows="8" placeholder="Description about the file you are attaching..."></textarea>
			        			</form>
			        		</div>
			        		<div class="modal-footer">
			          			<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
			          			<button type="button" class="btn btn-primary" onclick="document.getElementById('new-attachment-form').submit();">Add Attachment</button>
			        		</div>
			      		</div>
			    	</div>
			  	</div>
			  	
			  	<?php 
				if($this->session->userdata('level'))
				{ ?>
				  	<div class="modal fade" id="edit-department" tabindex="-1" role="dialog" aria-labelledby="edit-department-label" aria-hidden="true">
				    	<div class="modal-dialog">
				      		<div class="modal-content">
				        		<div class="modal-header">
				          			<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				          			<h4 class="modal-title">Edit Department</h4>
				        		</div>
				        		
				        		<div class="modal-body">
				        			<form id="edit-department-form" action="<?php echo base_url(); ?>departments/update/<?php echo $department[0]['department_id']; ?>" method="post">
				        				<div class="form-group">
				        					<label>Name</label>
				        					<input name="name" type="text" class="form-control" value="<?php echo $department[0]['department_name']; ?>" autocomplete="off">
				        				</div>
				        				
				        				<div class="form-group">
				        					<label>Assigned Users</label>
				        					<select name="assigned[]" class="form-control" multiple>
										    	<?php
										    	for($i = 0; $i < count($company_users); ++$i)
										    	{
										    		for($j = 0; $j < count($dept_users); ++$j)
										    		{
										    			if($company_users[$i]['id'] == $dept_users[$j]['id'])
										    			{ ?>
										    				<option value="<?php echo $company_users[$i]['id']; ?>" selected="selected"><?php echo $company_users[$i]['first_name'].' '.$company_users[$i]['last_name']; ?></option>
										    				<?php $company_users[$i] = NULL; ?>
										    			<?php
										    			} ?>
										    		<?php
										    		} ?>
										    	<?php
										    	} ?>
			
										    	<?php
												$company_users = array_values($company_users);
			
												for($i = 0; $i < count($company_users); ++$i)
												{
													if($company_users[$i] != NULL)
													{ ?>
														<option value="<?php echo $company_users[$i]['id']; ?>"><?php echo $company_users[$i]['first_name'].' '.$company_users[$i]['last_name']; ?></option>
													<?php
													}
												} ?>
									    	</select>
				        				</div>
				        				
				        				<div class="form-group">
				        					<label>Assigned Projects</label>
				        					<select name="projects[]" class="form-control" multiple>
										    	<?php
										    	for($i = 0; $i < count($company_projects); ++$i)
										    	{
										    		for($j = 0; $j < count($dept_projects); ++$j)
										    		{
										    			if($company_projects[$i]['project_id'] == $dept_projects[$j]['project_id'])
										    			{ ?>
										    				<option value="<?php echo $company_projects[$i]['project_id']; ?>" selected="selected"><?php echo $company_projects[$i]['project_name']; ?></option>
										    				<?php $company_projects[$i] = NULL; ?>
										    			<?php
										    			} ?>
										    		<?php
										    		} ?>
										    	<?php
										    	} ?>
			
										    	<?php
												$company_projects = array_values($company_projects);
			
												for($i = 0; $i < count($company_projects); ++$i)
												{
													if($company_projects[$i] != NULL)
													{ ?>
														<option value="<?php echo $company_projects[$i]['project_id']; ?>"><?php echo $company_projects[$i]['project_name']; ?></option>
													<?php
													}
												} ?>
									    	</select>
				        				</div>
				        				
				        				<div class="form-group">
					        				<label>Description</label>
					        				<textarea name="description" class="form-control" rows="8" placeholder="Describe the department..."><?php echo $department[0]['department_description']; ?></textarea>
			        					</div>
				        			</form>
				        		</div>
				        		
				        		<div class="modal-footer">
				          			<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
				          			<button type="button" class="btn btn-primary" onclick="document.getElementById('edit-department-form').submit();">Update</button>
				        		</div>
				        	</div>
				        </div>
				    </div>
				<?php 
				} ?>
			  	
			  	<ul class="nav nav-tabs" style="margin-bottom:15px;">
					<li class="active"><a href="#summary" data-toggle="tab">Summary</a></li>
		            <li class=""><a href="#projects" data-toggle="tab">Projects (<?php echo $department[0]['department_num_projects']; ?>)</a></li>
		          	<li class="visible-lg"><a href="#open" data-toggle="tab">Open (<?php echo $department[0]['department_num_tickets_open']; ?>)</a></li>
		          	<li class="visible-lg"><a href="#closed" data-toggle="tab">Closed (<?php echo $department[0]['department_num_tickets_completed']; ?>)</a></li>
		          	<li class="visible-lg"><a href="#users" data-toggle="tab">Users (<?php echo $department[0]['department_num_users']; ?>)</a></li>
		          	<li class="visible-lg"><a href="#attachments" data-toggle="tab">Attachments (<?php echo $department[0]['department_num_files']; ?>)</a></li>
				</ul>
		             
				<div class="tab-content">
					<div class="tab-pane active in" id="summary">
						<div class="row">
							<div class="col-lg-1"><strong>Name:</strong></div>
							<div class="col-lg-11"><?php echo $department[0]['department_name']; ?></div>
						</div>
					
						<div class="row">	
							<div class="col-lg-1"><strong>Created:</strong></div>
							<div class="col-lg-11"><?php echo date("m/d/Y", strtotime($department[0]['department_creation_date'])); ?></div>
						</div>
						
						<div class="row">		
							<div class="col-lg-1"><strong>About:</strong></div>
							<div class="col-lg-11"><?php echo nl2br($department[0]['department_description']); ?></div>
							<br>
						</div>
					</div>
					
					<div class="tab-pane in" id="projects">
						<?php 
		        		if($projects)
		        		{ ?>
			        		<table class="table table-striped table-bordered table-hover datatables">
								<thead>
							    	<tr>
									    <th>Project Name<span class="sort-icon"><span></th>
							    	</tr>
							  	</thead>
							  	<tbody>
							  		<?php 
							  		for($i = 0; $i < count($projects); ++$i)
							  		{ ?>
								    	<tr>
									      	<td><a href="<?php echo base_url(); ?>projects/view/<?php echo $projects[$i]['project_id']; ?>"><?php echo $projects[$i]['project_name']; ?></a></td>
								    	</tr>
								    <?php 
							  		} ?>
							    </tbody>
							</table>
						<?php 
		        		} 
		        		else 
		        		{ ?>
		        			<p>This department has no projects assigned.</p>
		        		<?php
		        		} ?>
					</div>
					
					<div class="tab-pane in" id="open">
						<?php 
				  		if($open_tickets)
				  		{ ?>
			        		<table class="table table-striped table-bordered table-hover datatables">
								<thead>
							    	<tr>
									    <th>Title<span class="sort-icon"><span></th>
									    <th>Due<span class="sort-icon"><span></th>
									    <th>Severity<span class="sort-icon"><span></th>
							    	</tr>
							  	</thead>
							  	<tbody>
						  			<?php 
							  		for($i = 0; $i < count($open_tickets); ++$i)
							  		{ ?>
								    	<tr>
									      	<td><a href="<?php echo base_url(); ?>tickets/view/<?php echo $open_tickets[$i]['tickets_id']; ?>"><?php echo $open_tickets[$i]['tickets_title']; ?></a></td>
									      	<td><?php echo date('m/d/y', strtotime($open_tickets[$i]['tickets_desired_completion'])); ?></td>
									      	<td>
									      		<?php 
									      		$severity = $open_tickets[$i]['tickets_severity_description'];
									      		
									      		if($severity == 'Critical')
									      		{
									      			echo "<span class='label label-danger'>{$severity}<span>";
									      		}
									      		elseif($severity == 'High')
									      		{
									      			echo "<span class='label label-warning'>{$severity}<span>";
									      		}
									      		elseif($severity == 'Medium')
									      		{
									      			echo "<span class='label label-info'>{$severity}<span>";
									      		}
									      		elseif($severity == 'Low')
									      		{
									      			echo "<span class='label label-success'>{$severity}<span>";
									      		} ?>
									      	</td>
								    	</tr>
								    <?php 
							  		} ?>
						  		
						  		</tbody>
							</table>
					  	<?php 
						} 
					  	else
					  	{ ?>
					  		<p>This department does not have any open tickets.</p>
					  	<?php 
					  	} ?>
					</div>
					
					<div class="tab-pane in" id="closed">
						<?php 
				  		if($closed_tickets)
				  		{ ?>
			        		<table class="table table-striped table-bordered table-hover datatables">
								<thead>
							    	<tr>
									    <th>Title<span class="sort-icon"><span></th>
									    <th>Due<span class="sort-icon"><span></th>
									    <th>Severity<span class="sort-icon"><span></th>
							    	</tr>
							  	</thead>
							  	<tbody>
						  			<?php 
							  		for($i = 0; $i < count($closed_tickets); ++$i)
							  		{ ?>
								    	<tr>
									      	<td><a href="<?php echo base_url(); ?>tickets/view/<?php echo $closed_tickets[$i]['tickets_id']; ?>"><?php echo $closed_tickets[$i]['tickets_title']; ?></a></td>
									      	<td><?php echo date('m/d/y', strtotime($closed_tickets[$i]['tickets_desired_completion'])); ?></td>
									      	<td>
									      		<?php 
									      		$severity = $closed_tickets[$i]['tickets_severity_description'];
									      		
									      		if($severity == 'Critical')
									      		{
									      			echo "<span class='label label-danger'>{$severity}<span>";
									      		}
									      		elseif($severity == 'High')
									      		{
									      			echo "<span class='label label-warning'>{$severity}<span>";
									      		}
									      		elseif($severity == 'Medium')
									      		{
									      			echo "<span class='label label-info'>{$severity}<span>";
									      		}
									      		elseif($severity == 'Low')
									      		{
									      			echo "<span class='label label-success'>{$severity}<span>";
									      		} ?>
									      	</td>
								    	</tr>
								    <?php 
							  		} ?>
						  		
						  		</tbody>
							</table>
					  	<?php 
						} 
					  	else
					  	{ ?>
					  		<p>This department does not have any closed tickets.</p>
					  	<?php 
					  	} ?>
					</div>
					
					<div class="tab-pane in" id="users">
						<?php 
				  		if($users)
				  		{ ?>
			        		<table class="table table-striped table-bordered table-hover datatables">
								<thead>
							    	<tr>
									    <th>Name<span class="sort-icon"><span></th>
									    <th>Title<span class="sort-icon"><span></th>
							    	</tr>
							  	</thead>
							  	<tbody>
						  			<?php 
							  		for($i = 0; $i < count($users); ++$i)
							  		{ ?>
								    	<tr>
									      	<td><a href="<?php echo base_url(); ?>index.php/users/view/<?php echo $users[$i]['id']; ?>"><?php echo $users[$i]['first_name'].' '.$users[$i]['last_name']; ?></a></td>
									      	<td><?php echo $users[$i]['user_job_title']; ?></td>
								    	</tr>
								    <?php 
							  		} ?>
						  		
						  		</tbody>
							</table>
					  	<?php 
						} 
					  	else
					  	{ ?>
					  		<p>This department does not have any users.</p>
					  	<?php 
					  	} ?>
					</div>
					
					<div class="tab-pane" id="attachments">
		                <div class="row">
		                	<div class="col-lg-12">
		                		<?php
				        		if($attachments)
				        		{ ?>
					        		<table class="table table-striped table-bordered table-hover datatables">
										<thead>
									    	<tr>
											    <th>Link</th>
											    <th>Uploaded By</th>
											    <th>Description</th>
											    <th>Comments</th>
											    <th>Action</th>
									    	</tr>
									  	</thead>
									  	<tbody>
									  		<?php
									  		for($i = 0; $i < count($attachments); ++$i)
									  		{ ?>
										    	<tr>
											    	<td><a href="<?php echo base_url().'assets/uploads/departments/'.$attachments[$i]['departments_files_hash_name']; ?>" target="_blank"><?php echo $attachments[$i]['departments_files_real_name']; ?></a></td>
											      	<td><a href="<?php echo base_url(); ?>index.php/users/view/<?php echo $attachments[$i]['id']; ?>"><?php echo $attachments[$i]['first_name'].' '.$attachments[$i]['last_name']; ?></a></td>
											      	<td><a href="javascript:;" data-toggle="modal" data-target="#file-description-<?php echo $department[0]['department_id']; ?>-<?php echo $attachments[$i]['departments_files_id']; ?>">Show</a></td>
											      	<td><a href="javascript:;" data-toggle="modal" data-target="#file-view-comments-<?php echo $department[0]['department_id']; ?>-<?php echo $attachments[$i]['departments_files_id']; ?>">Show (<?php if(count($file_comments[$i]) > 0) echo count($file_comments[$i]); else echo "0"; ?>)</a></td>
											      	<td class="text-center">
											      		<a style="color:#e74c3c;margin-right:5px;" href="<?php echo base_url(); ?>departments/remove/<?php echo $department[0]['department_id']; ?>/<?php echo $attachments[$i]['departments_files_id']; ?>"><i class="icon-remove"></i></a>
											      		<a style="color:#3498db;" href="javascript:;" data-toggle="modal" data-target="#file-create-comment-<?php echo $department[0]['department_id']; ?>-<?php echo $attachments[$i]['departments_files_id']; ?>"><i class="icon-pencil"></i></a>
											      	</td>
										    	</tr>
										    <?php
									  		} ?>
									    </tbody>
									</table>
								<?php
				        		}
				        		else
				        		{ ?>
				        			<p>This department does not have any attached files.</p>
				        		<?php
				        		} ?>
		                	</div>
		                </div>
					</div>
					
					<?php
		        	if($attachments)
		        	{ 
				  		for($i = 0; $i < count($attachments); ++$i)
				  		{ ?>
							<div class="modal fade" id="file-description-<?php echo $department[0]['department_id']; ?>-<?php echo $attachments[$i]['departments_files_id']; ?>" tabindex="-1" role="dialog" aria-labelledby="file-description-<?php echo $department[0]['department_id']; ?>-<?php echo $attachments[$i]['departments_files_id']; ?>" aria-hidden="true">
						    	<div class="modal-dialog">
						      		<div class="modal-content">
						        		<div class="modal-header">
						          			<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
						          			<h4 class="modal-title">File Description</h4>
						        		</div>
						        		<div class="modal-body">
						        			<?php echo nl2br($attachments[$i]['departments_files_description']); ?>
						        		</div>
						        		<div class="modal-footer">
						          			<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
						        		</div>
						      		</div>
						    	</div>
						  	</div>
						  	
						  	<div class="modal fade" id="file-view-comments-<?php echo $department[0]['department_id']; ?>-<?php echo $attachments[$i]['departments_files_id']; ?>" tabindex="-1" role="dialog" aria-labelledby="file-description-<?php echo $department[0]['department_id']; ?>-<?php echo $attachments[$i]['departments_files_id']; ?>" aria-hidden="true">
						    	<div class="modal-dialog">
						      		<div class="modal-content">
						        		<div class="modal-header">
						          			<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
						          			<h4 class="modal-title">File Comments</h4>
						        		</div>
						        		<div class="modal-body">
						        			<?php 
						        			if(count($file_comments[$i]) > 0)
						        			{
							        			for($j = 0; $j < count($file_comments[$i]); ++$j)
							        			{ ?>
							        				<p><a href="<?php echo base_url(); ?>index.php/users/view/<?php echo $file_comments[$i][$j]['id']; ?>"><?php echo $file_comments[$i][$j]['first_name'].' '.$file_comments[$i][$j]['last_name']; ?></a></p>
							        				<p><?php echo nl2br($file_comments[$i][$j]['department_files_comments_description']); ?></p>
							        				<?php 
							        				if($j != count($file_comments[$i]) - 1)
							        				{ ?>
							        					<hr>
							        				<?php 
							        				} 
						  						}
						  					} 
						  					else
						  					{ ?>
						  						This file has no comments.
						  					<?php 
							        		} ?>
						        		</div>
						        		<div class="modal-footer">
						          			<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
						        		</div>
						      		</div>
						    	</div>
						  	</div>
						  	
						  	<div class="modal fade" id="file-create-comment-<?php echo $department[0]['department_id']; ?>-<?php echo $attachments[$i]['departments_files_id']; ?>" tabindex="-1" role="dialog" aria-labelledby="file-description-<?php echo $department[0]['department_id']; ?>-<?php echo $attachments[$i]['departments_files_id']; ?>" aria-hidden="true">
						    	<div class="modal-dialog">
						      		<div class="modal-content">
						        		<div class="modal-header">
						          			<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
						          			<h4 class="modal-title">Create Comment</h4>
						        		</div>
						        		<div class="modal-body">
						        			<form id="new-file-comment-form-<?php echo $department[0]['department_id']; ?>-<?php echo $attachments[$i]['departments_files_id']; ?>" action="<?php echo base_url(); ?>departments/comment/<?php echo $department[0]['department_id']; ?>/<?php echo $attachments[$i]['departments_files_id']; ?>" method="post">
						          				<textarea name="comment" class="form-control" rows="8" placeholder="Type in your comment..."></textarea>
						        			</form>
						        		</div>
						        		<div class="modal-footer">
						          			<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
						          			<button type="button" class="btn btn-primary" onclick="document.getElementById('new-file-comment-form-<?php echo $department[0]['department_id']; ?>-<?php echo $attachments[$i]['departments_files_id']; ?>').submit();">Create Comment</button>
						        		</div>
						      		</div>
						    	</div>
						  	</div>
						<?php 
				  		} 
		        	} ?>
				</div>
			</div>
		</div>
	</div>
	<?php echo $footer ?>